// 对axios进行二次封装
import axios from 'axios'

 function getWordList(){
    return axios.get('http://project.x-zd.net:3001/apis/songword').then(res => res.data)
   
}
export  async function  parseLyrics(){
    const res = await getWordList()
    const Arr = res.data.split('\n').slice(1)
   //console.log(Arr)
    const wordList = []
    const regex = /^\[(\d{2}:\d{2}\.\d{2})\](.*)$/;
    const timeReg = /^(\d{2}):(\d{2})\./
    Arr.forEach(item => { 
        const match = item.match(regex)
     
        //console.log(match)
        if (match) {
            const [_,time, word] = match
            const [min, sec] = time.match(timeReg).slice(1).map(Number)
            const timeStamp = min * 60 + sec
            wordList.push({ timeStamp, word })
        }
    })
    //console.log(wordList)
    return wordList
   
}